# 1创建蓝图 & 2添加蓝图路由
from flask import Blueprint

# 创建蓝图对象
users_bp = Blueprint('users', __name__)

# 添加蓝图路由
@users_bp.route('/index')
def indext():
    return 'users bp response'

# 3.注册蓝图
from flask import Flask
# 导入蓝图
from apps.users_bp import users_bp

# 创建Flask实例
app = Flask(__name__)
# 注册蓝图,url_prefix指定访问的子路由
app.register_blueprint(users_bp,url_prefix='/users')

if __name__ == '__main__':
    # 查看路由映射
    print(app.url_map)
    app.run()


from flask import Blueprint
from flask import request
from flask import jsonify
import json
import datetime
import random
from database import db

bp_coupon =Blueprint('coupon',__name__)

@bp_coupon.route('/add',methods=['POST','GET'])
def add():
    if request.method == "POST":
        #获取vue发过来的参加
        data = json.loads(request.data)
        print(data)
        code = datetime.datetime.strftime(datetime.datetime.now(),'%Y%m%d%H%m%s')+str(random.randint(10000,99999))
        total = int(data['count'])
        #调用database里面的添加insert方法进行添加
        try:
             db.insert(sql)
             return jsonify({'code':200})
        except:
             return jsonify({'code':10010})
    else:
        return '获取'